﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SdmxMl.Structure;
using SdmxMl.Common;
using SdmxMl.Excel;

namespace SasPlugIn.Table
{
    /// <summary>
    /// Class for generation of SAS Table for Artefact attributes (1 row always)
    /// </summary>
    public class MaintenableArtefactTable : BaseSasTable
    {
        #region Constructor

        /// <summary>
        /// C'tor for generation of a SAS table holding Maintenable artefact row information
        /// </summary>
        /// <param name="maintenableArtefact">an object of Artefact type</param>
        /// <param name="tableName">Name of Sas table</param>
        /// <param name="prefix">Prefix for sas table</param>
        public MaintenableArtefactTable(Artefact maintenableArtefact, string tableName, string prefix)
            : base (maintenableArtefact, tableName, prefix) 
        {
            FillHeader();
        }

        /// <summary>
        /// Fill Header columns according to artefact attributes
        /// </summary>
        protected override void FillHeader()
        {
            header.Add(new HeaderColumn("AgencyID"));
            header.Add(new HeaderColumn("ID"));
            header.Add(new HeaderColumn("Version", 10));

            foreach (string lg in LangSupport.SupportedLanguages)
                header.Add(new HeaderColumn(INTERNATIONALIZED_NAME_PREFIX + lg, NAME_DEFAULT_LEN));

            foreach (string lg in LangSupport.SupportedLanguages)
                header.Add(new HeaderColumn(INTERNATIONALIZED_DESCR_PREFIX + lg, DESCRIPTION_DEFAULT_LEN));

            header.Add(new HeaderColumn("ValidFrom", 10));
            header.Add(new HeaderColumn("ValidTo", 10));

            // here Annotations always selected
            anInventory = new AnnotationInventory();
            anInventory.Inventory(artefact.AnnotationList, false);
            GenAnnotationHeader();
        }
        #endregion

        /// <summary>
        /// Prepares a list of string values representing a row of datas for table insertion
        /// </summary>
        protected override List<string> PrepareRowDatas(object o)
        {
            // Prepare row value list
            List<string> rowValues = new List<string>(header.Columns.Count);
            rowValues.Add(artefact.AgencyId);
            rowValues.Add(artefact.Id);
            rowValues.Add(artefact.Version);

            foreach (string lg in LangSupport.SupportedLanguages)
            {
                rowValues.Add(artefact.Name.GetForLanguage(lg));
            }

            foreach (string lg in LangSupport.SupportedLanguages)
            {
                rowValues.Add(artefact.Description.GetForLanguage(lg));
            }

            rowValues.Add(artefact.ValidFrom);
            rowValues.Add(artefact.ValidTo);

            // Annotations
            AddAnnotations(rowValues, artefact.AnnotationList);

            return rowValues;
        }


    }
}
